<template>
  <div class="movie_body" ref="movie_body">
    <Loading v-if="isLoading"/>
    <Scroller v-else :handleToScroll="handleToScroll" :handleToTouchEnd="handleToTouchEnd"> 
      <ul>
        <li class="pullDown">{{ pullDownMsg }}</li>
        <li v-for="item in hostFilm" :key="item.id">
          <div class="pic_show" @click="handleToDetail(item.id)">
            <img :src="item.img | setWH('128.180')" />
          </div>
          <div class="info_list">
            <div>
              <h2 class="move_name" @click="handleToDetail(item.id)">{{ item.nm }}</h2>
              <h2 class="move_type">{{ item.version }}</h2>
            </div>
            <p>
              观众评 <span class="grade">{{ item.sc }}</span>
            </p>
            <p>主演: {{ item.star }}</p>
            <p>{{ item.showInfo }}</p>
          </div>
          <div class="btn_mall" :style="'background:'+item.showStateButton.color">{{item.showStateButton.content}}</div>
        </li>
      </ul>
    </Scroller>
  </div>
</template>

<script>

export default {
  name: "nowPlaying",
  data() {
    return {
      hostFilm: [],
      pullDownMsg: "",
      isLoading:true,
      prevCityId:-1
    };
  },
  activated() {
    var cityId = this.$store.state.city.id;
    if(this.prevCityId === cityId)return;
    this.axios.get("/ajax/ajax/movieOnInfoList?ci="+cityId).then((res) => {
      if (res.status == 200) {
        this.hostFilm = res.data.movieList;
        this.isLoading = false;
        this.prevCityId = cityId;
      }
    });
    // this.axios({
    //     url:'https://m.maizuo.com/gateway?cityId=110100&pageNum=1&pageSize=10&type=1&k=7668896',
    //     headers:{
    //         'X-Client-Info': '{"a":"3000","ch":"1002","v":"5.0.4","e":"16338468372507882943741953","bc":"110100"}',
    //         'X-Host': 'mall.film-ticket.film.list'
    //     }
    // }).then(res=>{
    //     if(res.data.msg=="ok"){
    //         this.hostFilm = res.data.data.films;
    //     }
    // })
  },
  methods: {
    handleToDetail(movieId) {
      this.$router.push('/movie/Detail/1/'+movieId);
    },
    handleToScroll(pos) {
      if (pos.y > 30) {
        this.pullDownMsg = "正在更新";
      }
    },
    handleToTouchEnd(pos) {
      if (pos.y > 30) {
        this.axios.get("/ajax/ajax/movieOnInfoList?ci="+cityId).then((res) => {
          if (res.status == 200) {
            this.pullDownMsg = "更新成功";
            setTimeout(() => {
              this.hostFilm = res.data.movieList;
              this.pullDownMsg = "";
            }, 1000);
          }
        });
      }
    },
  },
};
</script>

<style scoped lang="scss">
.movie_body {
  flex: 1;
  overflow: auto;
  ul {
    margin: 0 12px;
    overflow: hidden;
    .pullDown {
      border: none;
      margin: 0;
    }
    li {
      display: flex;
      margin-top: 12px;
      padding-bottom: 10px;
      border-bottom: 1px solid #e6e6e6;
      align-items: center;
      .pic_show {
        width: 64px;
        height: 90px;
        img {
          width: 100%;
          display: block;
        }
      }
      .info_list {
        margin-left: 10px;
        width: calc(100% - 116px);
        h2 {
          vertical-align: middle;
          display: inline-block;
        }
        div {
          width: 100%;
          white-space: nowrap;
          overflow: hidden;
          .move_name {
            font-size: 17px;
            height: 24px;
            max-width: calc(100% - 25px);
            line-height: 24px;
            overflow: hidden;
            text-overflow: ellipsis;
            white-space: nowrap;
            margin-right: 5px;
          }
          .move_type {
            font-size: 9px;
            color: #fff;
            background-color: #d2d6dc;
            height: 14px;
            line-height: 14px;
            padding: 0 2px;
            border-radius: 2px;
          }
        }
        p {
          font-size: 13px;
          width: 200px;
          line-height: 22px;
          color: #666;
          overflow: hidden;
          text-overflow: ellipsis;
          white-space: nowrap;
          span {
            color: #faaf00;
            font-size: 15px;
            font-weight: bold;
          }
        }
      }
      .btn_mall {
        width: 47px;
        height: 27px;
        background: #f03d37;
        color: white;
        border-radius: 4px;
        font-size: 12px;
        text-align: center;
        line-height: 28px;
      }
    }
  }
}
</style>